﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kevin.Framework.Cache;
using System.Reflection;

/*  
 * 创建人：席吉波
 * 
 * 日期：  2010-09-11
 * 
 * 用途：  为提高效率，将动态生成的Assembly缓存起来
 *   
 */

namespace Kevin.Controls
{
    /// <summary>
    /// AssemblyChache 创建人：席吉波
    /// </summary>
    internal class ServiceAssemblyChache : CacheQueue<string, Assembly>
    {
        static ServiceAssemblyChache instance = null;
        private static object syncLock = new object();

        public static ServiceAssemblyChache Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncLock)
                    {
                        if (instance == null)
                            instance = CacheManager.GetInstance<ServiceAssemblyChache>();
                    }
                }
                return ServiceAssemblyChache.instance;
            }
        }



        public new void Add(string cacheKey, Assembly obj)
        {

            try
            {
                if (!instance.Contains(cacheKey))
                {
                    base.Add(cacheKey, obj);
                }
            }
            finally
            {

            }
        }

        public object GetData(string cacheKey)
        {
            Assembly result = null;
            if (base.TryGetValue(cacheKey, out result))
            {
                return result;
            }
            return result;
        }

        public new void Remove(string cacheKey)
        {
            base.Remove(cacheKey);
            //instance.Remove(cacheKey);
        }


        public bool Contains(string cacheKey)
        {

            try
            {
                return base.ContainsKey(cacheKey);
            }
            finally
            {

            }
        }
    }
}
